package com.example.parition;

import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Created with IntelliJ IDEA.
 * ClassName: WordCountStream
 * Package: com.example.wordcount
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-07-17
 * Time: 10:52
 */

//流处理 读文件
//流处理 wordCount案例
public class PartitionCustomDemo {
    public static void main(String[] args) throws Exception {
        //1.创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(2);

        //2.读取数据 从socket读
        DataStreamSource<String> hadoop102 = env.socketTextStream("hadoop102", 7777);

        DataStream<String> stringDataStream = hadoop102.partitionCustom(new MyPartitioner(), new KeySelector<String, String>() {
            @Override
            public String getKey(String s) throws Exception {
                return s;
            }
        });

        stringDataStream.print();


        env.execute();
    }
}
